import { Core } from './core';

export default class Shape extends Core.Element {
  // 类型
  type: string;

  canStroke:boolean = true;
  canFill:boolean = false;

  // 默认特征
  static defaultAttrs: Partial<Core.IAttr> = {
  }

  constructor(type: string, config: Partial<Core.IProp> = {}) {
    super(config);
    this.type = type;
    this.attrs = { ...Shape.defaultAttrs };
  }

  drawInner() {
    if (this.getProps('destroyed')) {
      return;
    }
    if (this.getProps('visible')) {
      
      
      const ctx = this.getProps('context');
      ctx.save();
      this.createPath();
      ctx.fillStyle = this.attrs.fillStyle;
      ctx.font = this.attrs.font;
      ctx.globalAlpha = this.attrs.globalAlpha;
      ctx.lineCap = this.attrs.lineCap;
      ctx.lineWidth = this.attrs.lineWidth;
      ctx.lineJoin = this.attrs.lineJoin;
      ctx.miterLimit = this.attrs.miterLimit;
      ctx.shadowBlur = this.attrs.shadowBlur;
      ctx.shadowColor = this.attrs.shadowColor;
      ctx.strokeStyle = this.attrs.strokeStyle;
      ctx.textAlign = this.attrs.textAlign;
      this.attrs.lineDash && ctx.setLineDash(this.attrs.lineDash);
      if(this.canFill){
        ctx.fill();
      }
      if (this.canStroke){
        ctx.stroke();
      }
      ctx.restore();
    }
  }
}